package com.cc.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.cc.dao.AdviceMapper;
import com.cc.dao.UserStudentMapper;
import com.cc.entity.Advice;
import com.cc.entity.UserStudent;
import com.cc.utils.Idgen;

@Service
public class AdviceService {
	@Resource  
    private AdviceMapper adviceDao;
	public int addAdvice(UserStudent currentUser,Advice newadv){
		if(currentUser.getSchoolid()==null||"".equals(currentUser.getSchoolid()))
			return 1;//学校id为空，无法提交意见
		if(newadv.getContent()==null||"".equals(newadv.getContent()))
			return 2;//意见为空
		newadv.setChecked("待查看");
		newadv.setId(Idgen.getUUID());
		newadv.setSchoolid(currentUser.getSchoolid());
		newadv.setStudentid(currentUser.getId());
		newadv.setTime(new Date());
		adviceDao.insert(newadv);
		return 0;
	}
	public List<Advice> getAllAdvice(UserStudent currentUser){
		List<Advice> record=adviceDao.selectByStudentId(currentUser.getId());
		return record;
	}
}
